package cn.com.xiaoyaoji.plugins.http;


import com.alibaba.fastjson.JSON;
import org.apache.http.HttpEntity;

public class ResponseMessage<T> {

	private int resultCode;
	private String responseBody;
	private HttpEntity entity;
	private String message;
	private T result;
	private String accessId;
	
	public int getResultCode() {
		return resultCode;
	}
	public void setResultCode(int resultCode) {
		this.resultCode = resultCode;
	}
	public String getAccessId() {
		return accessId;
	}
	public void setAccessId(String accessId) {
		this.accessId = accessId;
	}
	public String getResponseBody() {
		return responseBody;
	}
	public void setResponseBody(String responseBody) {
		this.responseBody = responseBody;
	}
	public HttpEntity getEntity() {
		return entity;
	}
	public void setEntity(HttpEntity entity) {
		this.entity = entity;
	}
	public T getResult() {
		return result;
	}
	public void setResult(T result) {
		this.result = result;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	// 将http的响应结果转化为标准响应对象
	public static <T1> ResponseMessage<T1> toObject(String response, Class<T1> clazz) {
		ResponseMessage<T1> resp = new ResponseMessage<T1>();
		resp.setResult(JSON.parseObject(response, clazz));
        return resp;
    }
	
	// 将http的响应结果转化为标准响应集合
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static <T1> ResponseMessage<T1> toList(String response, Class<T1> clazz) {
		ResponseMessage resp = new ResponseMessage();
		resp.setResult(JSON.parseArray(response, clazz));
        return resp;
    }

}
